package com.bobo.controller.user;

import com.bobo.dto.VoucherPageQueryDTO;
import com.bobo.dto.VoucherRequestDTO;
import com.bobo.entity.Category;
import com.bobo.entity.Voucher;
import com.bobo.result.Result;
import com.bobo.service.VoucherService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userVoucherController")
@RequestMapping("/user/voucher")
@Api(tags="C端优惠券相关接口")
@Slf4j
public class VoucherController {
    @Autowired
    private VoucherService voucherService;

    /**
     * 抢优惠券下单（未支付）
     * @param voucherRequestDTO
     * @return
     */
    @PostMapping("/order")
    public Result<Long> getVoucher(@RequestBody VoucherRequestDTO voucherRequestDTO) throws InterruptedException {
        Long id = voucherRequestDTO.getId();
        return  voucherService.getVoucher(id);
    }

    /**
     * 查询优惠券
     * @return
     */
    @PostMapping("/list")
    public Result<List<Voucher>> list (@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize) {
        VoucherPageQueryDTO dto = new VoucherPageQueryDTO();
        dto.setPage(page);
        dto.setPageSize(pageSize);
        List<Voucher> list = voucherService.getVoucherByPage(dto);
        return Result.success(list);
    }

}
